package com.example.ioc;

// 通过spring控制翻转
public class NewCarExample2 {
    public static void main(String[] args) {
        // 这样我们如果修改其他的功能 如添加个颜色的功能 我们就不需要改动其他的类
        // 只需要关注(功能)对应的类就可以了
        // 这样就实现代码的解耦 修改程序不必大动干戈 程序之间不影响 维护性高
        Tire tire = new Tire(20, "red");
        Bottom bottom = new Bottom(tire);
        Framework framework = new Framework(bottom);
        Car car = new Car(framework);
        car.init();
    }

    static class Car {
        private Framework framework;
        public Car (Framework framework) {
            this.framework = framework;
        }
        public void init() {
            framework.init();
        }
    }

    static class Framework {
        private Bottom bottom;
        public Framework(Bottom bottom) {
            this.bottom = bottom;
        }
        public void init() {
            bottom.init();
        }
    }

    static class Bottom {
        private Tire tire;
        public Bottom(Tire tire) {
            this.tire = tire;
        }
        public void init() {
            tire.init();
        }
    }

    static class Tire {
        private int size;
        private String color;
        public Tire (int size, String color) {
            this.size = size;
        }
        public void init() {
            System.out.println("轮胎尺寸: " + size + "轮胎颜色: " + color);
        }
    }
}
